{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #String Rotation LCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #LCCI"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string #string-matching"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串 #字符串匹配"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isFlipedString"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #字符串轮转"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>字符串轮转。给定两个字符串<code>s1</code>和<code>s2</code>，请编写代码检查<code>s2</code>是否为<code>s1</code>旋转而成（比如，<code>waterbottle</code>是<code>erbottlewat</code>旋转后的字符串）。</p>\n",
    "\n",
    "<p><strong>示例1:</strong></p>\n",
    "\n",
    "<pre><strong> 输入</strong>：s1 = &quot;waterbottle&quot;, s2 = &quot;erbottlewat&quot;\n",
    "<strong> 输出</strong>：True\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例2:</strong></p>\n",
    "\n",
    "<pre><strong> 输入</strong>：s1 = &quot;aa&quot;, s2 = &quot;aba&quot;\n",
    "<strong> 输出</strong>：False\n",
    "</pre>\n",
    "\n",
    "<ol>\n",
    "</ol>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ol>\n",
    "\t<li>字符串长度在[0, 100000]范围内。</li>\n",
    "</ol>\n",
    "\n",
    "<p><strong>说明:</strong></p>\n",
    "\n",
    "<ol>\n",
    "\t<li>你能只调用一次检查子串的方法吗？</li>\n",
    "</ol>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [string-rotation-lcci](https://leetcode.cn/problems/string-rotation-lcci/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [string-rotation-lcci](https://leetcode.cn/problems/string-rotation-lcci/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        n = len(s1)\n",
    "        if n == 0:\n",
    "            return True\n",
    "        for i in range(n):\n",
    "            if s1 == s2[i:] + s2[:i]:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        s1 = list(s1)\n",
    "        s2 = list(s2)\n",
    "        \n",
    "        s1.sort()\n",
    "        s2.sort()\n",
    "\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        s1,s2=list(s1),list(s2)\n",
    "        s1.sort()\n",
    "        s2.sort()\n",
    "        if s1==s2:\n",
    "            return True\n",
    "        else:return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        return s2 in s1 + s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        else:\n",
    "            if s1 == s2:\n",
    "                return True\n",
    "            for i in range(0, len(s1)):\n",
    "                if (s1[i:] + s1[:i]) == s2:\n",
    "                    return True\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        for i,ss in enumerate(s1):\n",
    "            if s1[i:] +s1[:i] == s2:\n",
    "                return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) == len(s2):\n",
    "            if s2 in s1 + s1:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s2 == s1 == '':\n",
    "            return True\n",
    "        A = list(s1)\n",
    "        B = list(s2)\n",
    "        for i in range(len(B)):\n",
    "            B.insert(0,B.pop())\n",
    "            if A == B:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) == len(s2) <= 1 and s1 == s2:\n",
    "            return True\n",
    "        for i in range(len(s1)):\n",
    "            if s1[i:]+s1[:i] == s2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        return s1 in s2 * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2 == \"\": return True\n",
    "        if len(s1) != len(s2): return False\n",
    "        #   输入：s1 = \"waterbottle\", s2 = \"erbottlewat\"\n",
    "        #  输出：True\n",
    "        for i in range(len(s1)):\n",
    "            if s2[i:] + s2[:i] == s1: return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return sorted(s1) == sorted(s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        len_s1 = len(s1)\n",
    "        len_s2 = len(s2)\n",
    "        if len_s1 != len_s2:\n",
    "            return False\n",
    "        elif len_s1 == 0:\n",
    "            return True\n",
    "        else:\n",
    "            for i in range(len_s2):\n",
    "                tmp_L = s2[:i]\n",
    "                tmp_R = s2[i:]\n",
    "                tmp = tmp_R + tmp_L\n",
    "                if tmp == s1:\n",
    "                    return True\n",
    "        return False\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        return s2 in s1 + s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        # brute force, time O(n^2)\n",
    "        m, n = len(s1), len(s2)\n",
    "        if m != n:\n",
    "            return False\n",
    "        if n == 0:\n",
    "            return True\n",
    "        for shift in range(n): # 轮转shift位\n",
    "            for i in range(n): # 然后比较是不是都相等\n",
    "                if s1[(shift + i) % n] != s2[i]:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        if len(s1) == 0 and len(s2) == 0:\n",
    "            return True\n",
    "        for i in range(len(s1)):\n",
    "            if s1[i:] + s1[:i] == s2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)>0 and len(s2) == 0:\n",
    "            return False\n",
    "        return (s1+s1).find(s2) >= 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        if s2 in s1+s1:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        # 我的解法\n",
    "        # if len(s1) != len(s2):\n",
    "        #     return False\n",
    "        # if len(s1) == 0 and len(s2) == 0:\n",
    "        #     return True\n",
    "        # for i in range(len(s1)):\n",
    "        #     tmp = s1[i+1:] + s1[0: i + 1]\n",
    "        #     if tmp == s2:\n",
    "        #         return True\n",
    "        # return False\n",
    "\n",
    "        # 题解，太强了，经旋转后的字符两个拼接，必然包含原字符\n",
    "        return len(s1) == len(s2) and s1 in (s2 + s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in s2 + s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        m=len(s1)\n",
    "        n=len(s2)\n",
    "\n",
    "        if(m!=n):\n",
    "            return False\n",
    "        if(s1==\"\" and s2==\"\"):\n",
    "            return True\n",
    "\n",
    "        i=0\n",
    "        j=0\n",
    "        while i<m:\n",
    "            while j<m :\n",
    "                if(s1[i]==s2[j]):\n",
    "                   s=s2[j:]+ s2[:j]\n",
    "                   if(s==s1):\n",
    "                       return True\n",
    "                j+=1\n",
    "            i+=1\n",
    "        return False\n",
    "                    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s2 == \"\" and s1 == \"\":\n",
    "            return True\n",
    "        if s2 == \"\" or len(s1) != len(s2):\n",
    "            return False\n",
    "        s1 += s1\n",
    "        if s1.find(s2) >= 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "\n",
    "        for i, char in enumerate(s2):\n",
    "            if char != s1[0]:\n",
    "                continue\n",
    "            \n",
    "            temp = s2[i:] + s2[0:i]\n",
    "\n",
    "            if temp == s1:\n",
    "                return True\n",
    "\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1 + s1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        \n",
    "        if s1==s2:\n",
    "            return True\n",
    "        \n",
    "        for i in range(len(s2)):\n",
    "            if s1[0]!=s2[i]:\n",
    "                continue\n",
    "            if s2[i:] + s2[:i] == s1:\n",
    "                return True\n",
    "        return False\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        m,n =len(s1),len(s2)\n",
    "        if m !=n:\n",
    "            return False\n",
    "        if n == 0:\n",
    "            return True\n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if s1[(i+j) % n] !=s2[j]:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in (s1 + s1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2): return False\n",
    "        if s1 == \"\": return True\n",
    "        \n",
    "        length = len(s1)\n",
    "        start = s2[0]\n",
    "        for count, i in enumerate(s1):\n",
    "            if i == start and s1[count:] == s2[:length-count] and s1[:count] == s2[length-count:]:\n",
    "                return True\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1 + s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        return s2 in s1 * 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        if s1==s2:\n",
    "            return True\n",
    "\n",
    "        for i in range(len(s2)):\n",
    "            if s2[i]==s1[0]:\n",
    "                tmp = s2[i:]+s2[0:i]\n",
    "                if (s1==tmp):\n",
    "                    return True\n",
    "\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        if s1==s2:\n",
    "            return True\n",
    "        n=len(s1)\n",
    "        for i in range(n):\n",
    "            s=s1[i+1:]+s1[:i+1]\n",
    "            # print(s)\n",
    "            if s==s2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        return s2 in s1 + s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in s2 + s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        '''\n",
    "        1，判断s1和s2长度是否相同\n",
    "        2，s2s2是否包含s1。\n",
    "\n",
    "        '''\n",
    "        if len(s1)==len(s2) and s1 in s2+s2:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        m, n = len(s1), len(s2)\n",
    "        if m != n:\n",
    "            return False\n",
    "        if n == 0:\n",
    "            return True\n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if s1[(i + j) % n] != s2[j]:\n",
    "                    break\n",
    "            else:\n",
    "                return True\n",
    "        return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        return s2 in s1*2\n",
    "\n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        if len(set(s1))!=len(set(s2)):\n",
    "            return False\n",
    "        elif s1==s2:\n",
    "            return True\n",
    "        else:\n",
    "            for i in range(len(s1)-1):\n",
    "                if s1[i+1:]+s1[:i+1]==s2:\n",
    "                    return True\n",
    "                    break\n",
    "            else:\n",
    "                return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in (s2 + s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if not s1 and not s2:\n",
    "            return True\n",
    "        return s2 in s1+s1 if s2 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) < len(s2):\n",
    "            return False\n",
    "        # 带旋转的都可以将原数组复制一倍对比判断\n",
    "        s2 += s2\n",
    "        return True if s1 in s2 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        \"\"\"\n",
    "        m=len(s1)\n",
    "        n=len(s2)\n",
    "\n",
    "        if(m!=n):\n",
    "            return False\n",
    "        if(s1==\"\" and s2==\"\"):\n",
    "            return True\n",
    "\n",
    "        i=0\n",
    "        j=0\n",
    "        while i<m:\n",
    "            while j<m :\n",
    "                if(s1[i]==s2[j]):\n",
    "                   s=s2[j:]+ s2[:j]\n",
    "                   if(s==s1):\n",
    "                       return True\n",
    "                j+=1\n",
    "            i+=1\n",
    "        return False\n",
    "        \"\"\"\n",
    "\n",
    "        m, n = len(s1), len(s2)\n",
    "        if m != n:\n",
    "            return False\n",
    "        if n == 0:\n",
    "            return True\n",
    "        for i in range(n):\n",
    "            for j in range(n):\n",
    "                if s1[(i + j) % n] != s2[j]:\n",
    "                    break\n",
    "            \n",
    "            else:return True\n",
    "            #当循环正常结束时，else部分的代码会被执行。如果循环是通过break语句提前结束的，那么else部分会被跳过。\n",
    "        return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1)!=len(s2):\n",
    "            return False\n",
    "        if s1==s2:\n",
    "            return True\n",
    "        for i in range(1,len(s1)):\n",
    "            if s1[i:]+s1[:i]==s2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in s2 + s2\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s1 == s2:\n",
    "            return True\n",
    "        \n",
    "        for i in range(0, len(s1)):\n",
    "            s1 = s1[1:] + s1[0]\n",
    "            if s1 == s2:\n",
    "                return True\n",
    "        \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        tmp = s2 * 2\n",
    "        return s1 in tmp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1)==len(s2) and s2 in s1*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in (s2+s2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in s2 + s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s2 == \"\" and s1 == \"\":\n",
    "            return True\n",
    "        if s2 == \"\" or len(s1) != len(s2):\n",
    "            return False\n",
    "        s1 += s1\n",
    "        print(s1.find(s2))\n",
    "        if s1.find(s2) >= 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1 + s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s1 in (s2 + s2)\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "      return len(s1) == len(s2) and s2 in s1+s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in (s1+s1)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1+s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return True if len(s1) == len(s2) and s2 in (s1 + s1) else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if(not s1 and not s2):\n",
    "            return True\n",
    "        return s2 in (s1+s1[:-1]) if s1 and s2 else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        if len(s1) == 0 and len(s2) == 0:\n",
    "            return True\n",
    "        for i in range(len(s1)):\n",
    "            tmp = s1[i+1:] + s1[0: i + 1]\n",
    "            if tmp == s2:\n",
    "                return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s2) < 1 and len(s1) > 1:\n",
    "            return False \n",
    "            \n",
    "        if s2 in s1+s1:\n",
    "            return True \n",
    "        else:\n",
    "            return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1 + s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s2) != len(s1):\n",
    "            return False \n",
    "        else:\n",
    "            if s2 in s1+s1:\n",
    "                return True \n",
    "            else:\n",
    "                return False "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) == len(s2) and all(_s1 in s2 for _s1 in s1):\n",
    "            if len(s1) == 0:\n",
    "                return True\n",
    "            for k in range(len(s1)):\n",
    "                if s2[:(len(s1) - k)] == s1[k:] and s2[(len(s1) - k):] == s1[:k]:\n",
    "                    return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        if len(s1) != len(s2):\n",
    "            return False\n",
    "        \n",
    "        if s2 in  s1+s1:\n",
    "            return True\n",
    "        \n",
    "        else:\n",
    "            return False\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if not s1 and not s2:\n",
    "            return True\n",
    "        s11 = \"\"\n",
    "        for i in s1:\n",
    "            s1 = s1.replace(i, \"\", 1)\n",
    "            s11 = s11 + i\n",
    "            if s1 + s11 == s2:\n",
    "                return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        return len(s1) == len(s2) and s2 in s1+ s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) == len(s2):\n",
    "            return s1 in s2+s2\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s2 == \"\" and s1 == \"\":\n",
    "            return True\n",
    "        if s2 == \"\":\n",
    "            return False\n",
    "        s1 += s1\n",
    "        print(s1.find(s2))\n",
    "        if s1.find(s2) >= 0:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "\n",
    "        return len(s1) == len(s2) and s1 in s2 + s2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        len_s1 = len(s1)\n",
    "        len_s2 = len(s2)\n",
    "        \n",
    "        if len_s1 != len_s2:\n",
    "            return False\n",
    "        \n",
    "        if len_s1 == len_s2 and len_s1 == 0:\n",
    "            return True\n",
    "        \n",
    "        for i in range(len_s1):\n",
    "            shuffle_s1 = s1[i:] + s1[:i]\n",
    "            if shuffle_s1 == s2:\n",
    "                return True\n",
    "            \n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        # return s1 in s2+s2 and s2 in s1+s1\n",
    "        # return len(s1) == len(s2) and s2 in s1+s1\n",
    "        return len(s1) == len(s2) and s2 in s1 + s1\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        i, j = 0, 0\n",
    "        m, n = len(s1), len(s2)\n",
    "        if m != n:\n",
    "            return False\n",
    "        if not m:\n",
    "            return True\n",
    "        for offset in range(n):\n",
    "            flag = 1\n",
    "            for i in range(offset, n):\n",
    "                if (s1[i] != s2[i-offset]):\n",
    "                    flag = 0\n",
    "                    break\n",
    "            if not flag:\n",
    "                continue\n",
    "            for j in range(offset):\n",
    "                if s1[j] != s2[n-offset+j]:\n",
    "                    flag = 0\n",
    "                    break\n",
    "            if flag:\n",
    "                return True\n",
    "        return False\n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if not s1 and not s2:\n",
    "            return True\n",
    "        s11 = \"\"\n",
    "        for i in s1:\n",
    "            s1 = s1.replace(i, \"\", 1)\n",
    "            s11 = s11 + i\n",
    "            if s1 + s11 == s2:\n",
    "                return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if s1 in s2 * 2:\n",
    "            if len(s1) == len(s2):\n",
    "                return True\n",
    "        return False\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        m,n = len(s1),len(s2)\n",
    "        if m != n:\n",
    "            return False\n",
    "        p = 131\n",
    "        mod = 10**10\n",
    "        target = 0\n",
    "        cur = 0\n",
    "        m = 1\n",
    "        for i,j in enumerate(s1):\n",
    "            cur = (cur*p + ord(j)-96)%mod\n",
    "            target = (target*p+ord(s2[i])-96)%mod\n",
    "            m = m*p%mod\n",
    "        if cur == target:\n",
    "            return True\n",
    "        for j in s1:\n",
    "            cur = (cur*p-(ord(j)-96)*(m-1))%mod\n",
    "            if cur == target:\n",
    "                return True\n",
    "        return False\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s1) != len(s2): return False\n",
    "        if not s1 and not s2: return True\n",
    "        for i in range(len(s2) ):\n",
    "            tmp = s2[-i:] + s2[:-i]\n",
    "            if tmp == s1: return True\n",
    "        return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isFlipedString(self, s1: str, s2: str) -> bool:\n",
    "        if len(s2) < 1 and len(s1) > 1:\n",
    "            return False \n",
    "            \n",
    "        if s2 in s1+s1:\n",
    "            return True \n",
    "        else:\n",
    "            return False "
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
